import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> linkedList = new LinkedList<>();

        linkedList.addLast(1);
        linkedList.addLast(2);
        linkedList.addLast(3);
        linkedList.addLast(4);
        linkedList.addLast(1);
        //使用sout直接遍历
        System.out.println(linkedList);
        System.out.println("================");
        //使用for-each遍历
        for(Integer e : linkedList) {
            System.out.print(e + " ");
        }
        System.out.println("");
        System.out.println("================");
        //使用迭代器正序遍历
        ListIterator<Integer> its = linkedList.listIterator();
        while(its.hasNext()) {
            System.out.print(its.next() + " ");
        }
        System.out.println("");
        System.out.println("==================");
        //使用迭代器逆序遍历
        ListIterator<Integer> it = linkedList.listIterator(linkedList.size());
        while(it.hasPrevious()) {
            System.out.print(it.previous() + " ");
        }
        System.out.println("");
    }
    public static void main4(String[] args) {
        LinkedList<Integer> linkedList = new LinkedList<>();
        List<Integer> list = new LinkedList<>();

        linkedList.addLast(1);
        linkedList.addLast(2);
        linkedList.addLast(3);
        linkedList.addLast(4);
        linkedList.addLast(1);

        System.out.println(linkedList.indexOf(1));

        System.out.println(linkedList.lastIndexOf(1));

        List<Integer> list1 = linkedList.subList(2,4);
        System.out.println(list1);
    }
    public static void main3(String[] args) {
        //无参构造
        LinkedList<Integer> linkedList = new LinkedList<>();
        List<Integer> list = new LinkedList<>();

        linkedList.addLast(1);
        linkedList.addLast(2);
        linkedList.addLast(3);
        linkedList.addLast(4);

        System.out.println(linkedList);

        LinkedList<Integer> linkedList1 = new LinkedList<>(linkedList);
        linkedList1.addLast(89);

        System.out.println(linkedList1);
    }
    public static void main2(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(4);
        myLinkedList.addFirst(5);

        myLinkedList.addLast(99);

        myLinkedList.display();

        System.out.println(myLinkedList.size());

        myLinkedList.addIndex(3,99);

        myLinkedList.display();

        if (myLinkedList.contains(4)) {
            System.out.println(4 + "在链表中");
        }else {
            System.out.println(4 + "不在来链表中");
        }

        myLinkedList.remove(3);

        myLinkedList.removeAllKey(99);

        myLinkedList.display();

        myLinkedList.clear();
    }
    public static void main1(String[] args) {
        MySingleList mySingleList = new MySingleList();
        mySingleList.addFirst(1);
        mySingleList.addFirst(2);
        mySingleList.addFirst(3);
        mySingleList.addFirst(4);
        mySingleList.addFirst(5);

        mySingleList.addLast(89);

        mySingleList.addIndex(3,89);

        mySingleList.display();

        System.out.println(mySingleList.size());

        if (mySingleList.contains(5)) {
            System.out.println(5 + "在链表中");
        }else {
            System.out.println(5 + "不在链表中");
        }

        mySingleList.remove(89);

        mySingleList.removeAllKey(4);

        System.out.println(mySingleList.size());

        mySingleList.display();

        mySingleList.clear();
    }
}
